<!--
 * @Date: 2024-11-26 14:57:50
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2024-12-23 10:48:15
 * @Description: PreviewDrawer
-->
<template>
  <el-drawer v-model="drawerState.visible" :="drawerAttrs">
    <div class="hp-preview-main">
      <div class="hp-preview-header">
        <div class="title">预览</div>
        <el-button type="danger" @click="handleClose">关闭</el-button>
      </div>
      <div class="hp-preview-body">
        <HpRender :layouts="drawerState.layouts" :design="true"/>
      </div>
    </div>
  </el-drawer>
</template>

<script setup>
import { reactive } from 'vue';
import HpRender from '@hp/render/src/Render.vue'

const drawerAttrs = reactive({
  size: '100%',
  class: 'hp-preview',
  showClose: false,
  withHeader: false
})
const drawerState = reactive({
  layouts: [],
  visible: false
})

const handleOpen = (layouts) => {
  drawerState.layouts = layouts
  drawerState.visible = true
}
const handleClose = () => {
  drawerState.visible = false
}

defineExpose({
  handleOpen
})

</script>

<style lang="scss" scoped>
.hp-preview {
  &-main {
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  &-header {
    display: flex;
    align-items: center;
    padding: 8px;
    border: 1px solid #ececec;
    > :first-child {
      flex: 1;
    }
    .title {
      font-size: 16px;
    }
  }
  &-body {
    flex: 1;
    min-height: 100px;
    // padding: 8px;
  }
}
</style>
<style lang="scss">
.hp-preview {
  .el-drawer__body {
    margin: 0;
    padding: 0;
  }
}
</style>